package com.cn.springcloudwechat.serviceImpl.find;

import com.cn.springcloudwechat.common.utils.ErrorUtil;
import com.cn.springcloudwechat.mapper.mapper.find.askDoctor.YmDoctorWorkMapper;
import com.cn.springcloudwechat.model.find.askDoctor.YmDoctorWork;
import com.cn.springcloudwechat.service.find.askDoctor.YmDoctorWorkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;

import java.sql.Time;
import java.sql.Timestamp;

@Service("YmDoctorWorkService")
public class YmDoctorWorkServiceImpl implements YmDoctorWorkService{
    @Autowired
    YmDoctorWorkMapper ymDoctorWorkMapper;

    /**
     * 配置医生在线时间
     *
     * @param  ymDoctorWork
     *
     * @return
     */
    @Override
    public Integer insertYmDoctorWork(YmDoctorWork ymDoctorWork) {
        Time workStart = ymDoctorWork.getWorkStart();
        Time workEnd = ymDoctorWork.getWorkEnd();
        Long doctorId = ymDoctorWork.getDoctorId();
        Assert.notNull(workStart,String.format(ErrorUtil.PARAMETER_NULL,"workStart"));
        Assert.notNull(workEnd,String.format(ErrorUtil.PARAMETER_NULL,"workEnd"));
        Assert.notNull(doctorId,String.format(ErrorUtil.PARAMETER_NULL,"doctorId"));
        return ymDoctorWorkMapper.insertSelective(ymDoctorWork);
    }

    /**
     * 删除配置过的医生在线时间
     *
     * @param  ymDoctorWork
     *
     * @return
     */

    @Override
    public Integer deleteYmDoctorWork(YmDoctorWork ymDoctorWork) {
        Long doctorWorkId = ymDoctorWork.getDoctorId();
        Assert.notNull(doctorWorkId,String.format(ErrorUtil.PARAMETER_NULL,"doctorWorkId"));
        return ymDoctorWorkMapper.deleteByPrimaryKey(doctorWorkId);
    }
    /**
     * 根据医生ID查询医生在线时间
     *
     * @param  doctorId
     *
     * @return
     */
    @Override
    public YmDoctorWork queryYmDoctorWork(Long doctorId) {
        Assert.notNull(doctorId,String.format(ErrorUtil.PARAMETER_NULL,"doctorId"));
        return ymDoctorWorkMapper.queryByDoctorId(doctorId);
    }
    /**
     * 修改医生在线时间
     *
     * @param  ymDoctorWork
     *
     * @return
     */

    @Override
    public Integer updateYmDoctorWork(YmDoctorWork ymDoctorWork) {
        Long doctorWorkId = ymDoctorWork.getDoctorWorkId();
        Time workStart = ymDoctorWork.getWorkStart();
        Time workEnd = ymDoctorWork.getWorkEnd();
        Long doctorId = ymDoctorWork.getDoctorId();
        Assert.notNull(workStart,String.format(ErrorUtil.PARAMETER_NULL,"workStart"));
        Assert.notNull(workEnd,String.format(ErrorUtil.PARAMETER_NULL,"workEnd"));
        Assert.notNull(doctorId,String.format(ErrorUtil.PARAMETER_NULL,"doctorId"));
        Assert.notNull(doctorWorkId,String.format(ErrorUtil.PARAMETER_NULL,"doctorWorkId"));
        return ymDoctorWorkMapper.updateByPrimaryKeySelective(ymDoctorWork);
    }
}
